﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RaveEngine.Engine;
using RaveEngine.Engine.Query;
using RaveEngine.Engine.Config;
using System.Configuration;
using RaveEngine.Engine.Query.Translate;

namespace RaveEngine.Controllers
{
    public class RaveKeyController : Controller
    {
        public static RaveKeyConfig keyConfig 
        {
            get
            {
                if (_keyConfig == null)
                {
                    _keyConfig = new RaveKeyConfig(ConfigurationManager.AppSettings["raveKeyConfigPath"]); 
                }
                return _keyConfig;
            }
        }
        private static RaveKeyConfig _keyConfig = null;

        //
        // GET: /Rave/
        public ActionResult Index(string key)
        {
            BaseRaveQuery query;
            BaseRaveConfig kconfig = keyConfig[key];

            if (kconfig.GetType() == typeof(raveTranslateConfig))
            {
                query = new TranslateQuery() { config = kconfig };
            }
            else
            {
                query = new AggregateQuery();
                throw new NotImplementedException("Aggregate Query not yet implemented");
            }

            ViewData["Response"] = query.Execute();

            return View("~/Views/Rave/Index.aspx");
        }

    }
}
